package main.java.br.com.projeto.domain.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import main.java.br.com.projeto.domain.entity.Usuario;

public class DaoUsuario extends Dao<Usuario>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5932255030333355510L;

	public DaoUsuario() {
		super(Usuario.class);
	}
	
	public List<Usuario> listByFilter(Long id, String filter) {
		String hql = "select usuario from Usuario usuario "
				+ "left outer join usuario.perfil perfil "
				+ "where (lower(usuario.nome) like '%' || lower ( cast(:filter as string) ) || '%' or :filter = null) "
				+ "and (usuario.id = :id or :id = 0) ";

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("filter", filter);
		parameters.put("id", id);

		return this.findOneResult(hql, parameters);
	}
}
